home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_8 / issue_06 / risc_os / Wimp / Colours < prev    next >
Encoding:
Text File  |  1988-12-06  |  12.0 KB  |  302 lines

  1. > Wimp.Colours
  2.  
  3. New Calls
  4. ---------
  5.  
  6.         Wimp_SetMode
  7.         Wimp_SetPalette
  8.         Wimp_ReadPalette
  9.         Wimp_ReadPixTrans
  10.         Wimp_SetCaretPosition
  11.         Wimp_SetColour
  12.         Wimp_TextColour
  13.         Wimp_SetFontColours
  14.         Wimp_PlotIcon
  15.  
  16.         *Configure WimpMode <number>
  17.         *WimpPalette <filename>
  18.  
  19. Overview
  20. --------
  21.  
  22. The new Wimp has been designed to operate in any of the graphics modes
  23. available under Arthur, so that it is as easy as possible for applications to
  24. work without knowing much about which mode is currently in use.
  25.  
  26. When a task is the only client of the Wimp, it is OK for it to select the
  27. mode of its choice, and to always operate in that mode.  When many tasks are
  28. running simultaneously, however, each of the tasks must be prepared to work
  29. in whichever mode is currently selected, since they can't all decide that the
  30. mode will be what they want.
  31.  
  32. Under the new system, the choice of which mode and which palette to use is
  33. given to the user, rather than the application program - the central palette
  34. management utility provides the necessary facilities, and the other
  35. applications simply respond to whatever mode is currently in use.
  36.  
  37. To get round the problem of different modes having differing pixel aspect
  38. ratios, the Wimp performs automatic scaling of sprites, and also of the
  39. system font (see Wimp.Text).
  40.  
  41. To get round the palette problem, there is a common understanding of what
  42. each colour is used for, based on the 16 colours available in modes 9,12 and
  43. 20.  In modes with more or less colours, the Wimp uses a translation table to
  44. select the closest colours available.  The use of this table means that
  45. application programs should normally not have to worry about which mode is
  46. actually in use - as long as all colour selections are done through the Wimp,
  47. the best available colour will be chosen.
  48.  
  49. The standard colour uses are as follows:
  50.  
  51.        0-7  linear grey scale, usually from white (0) to black (7)
  52.                 (these colours are used for the anti-aliased fonts)
  53.                 (4 = scroll bar outer colour also)
  54.          8  yellow
  55.          9  blue
  56.         10  green
  57.         11  red
  58.         12  light    input focus background colour for title bar
  59.         13  light    normal background colour for title bar
  60.         14  dark     foreground colour for title bar (usually black)
  61.         15  darkish  desktop background colour
  62.  
  63. Applications should rely on these colours having been set up as above, and
  64. should not set the palette at all.  The palette is set up by the palette
  65. utility using the Wimp_SetPalette call, which associates an RGB value with
  66. each of the 16 wimp colours.  What effect this actually has on the screen
  67. palette is determined by the number of colours available as follows:
  68.  
  69. 1 bit per pixel (2 colours):
  70.  
  71. Palette:  colour 0 is set to wimp colour 0
  72.           colour 1 is set to wimp colour 7
  73.  
  74.        0  logical colour 0 - font background colour
  75.      1-6  ecf pattern 4 (stippled in one of 6 patterns with colours 0,1)
  76.        7  logical colour 1 - font foreground colour
  77.     8-14  either colour 0 or 1 (whichever is closest in brightness)
  78.       15  ecf pattern 4 (the closest brightness ecf is used)
  79.  
  80. 2 bits per pixel (4 colours):
  81.  
  82. Palette:  colours 0..3 are set to the linear greyscale from wimp colours 0 to 7
  83.  
  84.     0-15  logical colour with closest brightness
  85.  
  86. 4 bits per pixel (16 colours):
  87.  
  88. Palette:  all colours are set to their corresponding wimp colour
  89.  
  90.     0-15  same logical colour
  91.  
  92. 8 bits per pixel (256 colours):
  93.  
  94. Palette:  set to the default
  95.  
  96.     0-15  closest approximation to the R,G,B value set in the wimp palette
  97.  
  98.  
  99. Using the mode-independent facilities
  100. -------------------------------------
  101.  
  102. The Wimp colour table is used by the Wimp in the following circumstances:
  103.  
  104.         when reading the colours for a given window from its definition
  105.             - unless bit 10 of the window flags is set
  106.             - in this case the colours are used unchanged
  107.  
  108.         when reading the colours for an icon
  109.             - text colours are looked up in the table
  110.             - sprite colours are translated
  111.               if the sprite has 1,2 or 4 bits per pixel
  112.               (8 bit per pixel sprites are illegal as Wimp icons)
  113.  
  114.         when reading the caret colour
  115.             - default caret colour is wimp colour 11
  116.             - if bit 26 of R4 (Wimp_SetCaretPosition) set, bits 16..23 = colour
  117.             - if bit 27 of R4 set, this colour is a 'real' colour
  118.             - note that the EOR colour of the caret is EORed with wimp colour 0
  119.               (this only matters in 256-colour modes)
  120.               See Wimp.Text for further details.
  121.  
  122. In the above description, a 'real' colour is defined as follows:
  123.  
  124.    In non 256-colour modes, the colour is simply the logical colour
  125.    In 256-colour modes, bits 0..1 are bits 6..7 of the tint
  126.                         bits 2..7 are bits 0..5 of the colour (gcol)
  127.  
  128.  
  129. The Wimp colour table is not used if the application simply plots a sprite in
  130. its window, or if the GCOL command is used to set colours.
  131.  
  132. To select a Wimp colour explicitly, use:
  133.  
  134.         Wimp_SetColour
  135.         Entry:  R0=gcol action/wimp colour
  136.                    bits 0..3 = colour
  137.                    bits 4..6 = gcol action
  138.                    bit 7 = foreground / background colour flag
  139.         Exit:  appropriate gcol/tint commands have been issued
  140.                note that ecf pattern 4 may be used in 2-colour modes
  141.  
  142. Another call has been provided to facilitate the matching of (VDU 4) text
  143. colours to graphics colours (it is used by Wimp_CommandWindow and on exit
  144. from the Wimp).  For obvious reasons, however, it is unable to use an ECF
  145. pattern to represent grey levels in monochrome modes:
  146.  
  147.         Wimp_TextColour
  148.         Entry:  R0 = wimp colour/fg/bg
  149.                      bits 0..3 = colour
  150.                      bit 7 = foreground / background colour flag
  151.         Exit:   appropriate colour/tint commands have been issued
  152.  
  153. In a similar vein, the Wimp can set up anti-aliased font colours, either by
  154. programming the validation string of an icon (see Wimp.Icons), or by using
  155. the following explicit call:
  156.  
  157.         Wimp_SetFontColours
  158.         Entry:  R1 = wimp colour (background)
  159.                 R2 = wimp colour (foreground)
  160.  
  161. The Wimp works out how many colours can be used for anti-aliasing, and also
  162. takes care of mode-dependent decisions (eg. in 256-colour mode 16 shades can
  163. always be used, but in other modes the number of shades available depends on
  164. the colours).
  165.  
  166. NOTE: Applications should NOT assume the setting of the font colours after a
  167.       Wimp_Poll operation, but should instead explicitly set up the font
  168.       colours as required.  This also means that there is no need to reset
  169.       the font colours afterwards.
  170.  
  171. To plot an icon explicitly (inside a Redraw/Update loop), use:
  172.  
  173.         Wimp_PlotIcon
  174.         Entry:  R1 --> icon definition
  175.                  + 0..15  = bounding box (relative to window origin)
  176.                  + 16     = icon flags
  177.                  + 20..31 = icon data
  178.  
  179.  
  180. Setting the mode/palette
  181. ------------------------
  182.  
  183. Normally these calls will only be used by the palette utility, in response to
  184. spcific actions made by the user.  However, the calls are detailed here for
  185. reference:
  186.  
  187. To set up the default mode used by the Wimp on startup:
  188.  
  189.         *Configure WimpMode <number>
  190.  
  191. The next time the Wimp is started up, the specified mode is used.  The value
  192. is also remembered in CMOS RAM, so it is remembered after power-off.  On new
  193. machines, the default wimp mode is 12.
  194.  
  195. To change the Wimp mode in use:
  196.  
  197.         Wimp_SetMode
  198.         Entry:  R0 = mode number
  199.         Exit:   the Wimp palette is recomputed and re-output
  200.                 the pointer is reprogrammed
  201.                 the amount of screen memory is 'shrunk' as much as possible
  202.  
  203. If this call is made when no tasks are running, the mode change does not take
  204. place until a task is run.  Note that changes to the Wimp mode made in this
  205. way are remembered the next time the Wimp is run, but do not affect the
  206. configured mode and so are not remembered after switch-off.
  207.  
  208. To set up the palette from a file:
  209.  
  210.         *WimpPalette <filename>
  211.  
  212. Palette files are of type &FED, and can be in one of two formats (including
  213. or excluding the logical colour numbers).  On Arthur 2, FileSwitch defaults
  214. the runtype of palette files as follows:
  215.  
  216.         *Set Alias$@RunType_FED WimpPalette %0
  217.  
  218. Thus double-clicking a palette file from the Finder has the effect of
  219. activating that palette.
  220.  
  221. To set up the palette from RAM:
  222.  
  223.         Wimp_SetPalette
  224.         Entry:  R1 --> block of 20 words
  225.                   words 0..15 are the wimp colours
  226.                   word 16 is the border colour
  227.                   words 17..19 are the pointer colours (1,2,3)
  228.                   each word is of the form &BBGGRRxx (blue, green, red)
  229.  
  230. When this call is made, the palette is recomputed depending on the mode.  If
  231. the mode in use does not have 16 colours, this may cause the logical colour
  232. mapping used by the Wimp to change, which will necessitate a screen redraw. 
  233. The palette utility detects this automatically, and behaves appropriately.
  234.  
  235. To read the current Wimp palette settings:
  236.  
  237.         Wimp_ReadPalette
  238.         Entry:  R1 --> block of 20 words
  239.         Exit:   block set up from the Wimp palette
  240.                   words 0..15 are the wimp colours
  241.                   word 16 is the border colour
  242.                   words 17..19 are the pointer colours (1,2,3)
  243.                   each word is of the form &BBGGRRxx (blue, green, red)
  244.                   xx = actual 'real' colour used by Wimp
  245.                        (0 for border and mouse colours)
  246.  
  247. To read the current Wimp scale factors and pixel translation table (used for
  248. plotting icons which are sprites):
  249.  
  250.         Wimp_ReadPixTrans
  251.         Entry:  R0 = 0 ==> sprite is in the system area
  252.                    = &1xx ==> sprite is in a user area (R2 = name ptr)
  253.                    = &2xx ==> sprite is in a user area (R2 = sprite ptr)
  254.                 R1 = 0 ==> sprite is in the system area
  255.                    = 1 ==> sprite is in the Wimp's shareable area
  256.                    > 1 ==> R1 --> user sprite area
  257.                 R2 --> name of sprite (if R0 = &1xx or &0xx)
  258.                    --> sprite itself (if R0 = &2xx)
  259.                 R6 --> 4-word block to receive scale factors
  260.                 R7 --> 4-word block to receive pixel translation table
  261.         Exit:   [R6] = scale factors (x-mul,y-mul,x-div,y-div)
  262.                 [R7] = pixel translation table (16 bytes)
  263.  
  264. After this call, R6 and R7 can be passed to OS_SpriteOp (PutSpriteScaled). 
  265. The scale factors returned depend on the mode the sprite is defined in, and
  266. the mode currently in use by the Wimp - the Wimp will attempt to correct for
  267. aspect ratio changes between different modes.  Note that the pixel
  268. translation table is only suitable for use with sprites defined in 1,2 or 4
  269. bits per pixel, and the colours are translated as follows:
  270.  
  271.         Sprite mode     Colour associations
  272.         -----------     -------------------
  273.         1 bpp           colours 0,1 are treated as Wimp colours 0,7
  274.         2 bpp           colours 0..3 are treated as Wimp colours 0,2,4,7
  275.         4 bpp           colours 0..15 are treated as Wimp colours 0..15
  276.         8 bpp           the translation table is meaningless
  277.  
  278. Note that the format of the bytes returned in the pixel translation table is
  279. not the same as those returned by Wimp_ReadPalette in 256-colour modes.  The
  280. colours used when plotting sprites correspond to the actual values to be put
  281. into the screen memory, and are in the following format:
  282.  
  283.         bits 0..3 = palette register
  284.         bit     4 = bit 7 of red value
  285.         bit     5 = bit 6 of green value
  286.         bit     6 = bit 7 of green value
  287.         bit     7 = bit 7 of blue value
  288.  
  289. Since the default palette is defined as 'brtt' (blue, red, tint, tint), this
  290. means:
  291.  
  292.         Pixtrans    = BGGRbrtt
  293.         colour/tint = BBGGRRtt
  294.  
  295. To get the pixtrans value from the colour/tint, rotate bits 3..6 left by 1.
  296.  
  297. NOTE:  when programming the caret colour, the Wimp assumes that the colour
  298.        supplied (if bit 27 is set) is of the colour/tint form.  When passing
  299.        this value to the Font Manager, however, it must translate the value
  300.        into the 'pixtrans' form, since that is what the latter expects.
  301.  
  302.